package com.krdz.provider;

import org.apache.ibatis.jdbc.SQL;

import com.krdz.bean.PersonBean;
/**
 * 人员管理sql类
 * @author dinghao
 *
 * @date  2018年11月15日
 */
public class PersonProvider {
	
	//查询人员信息
	public String findPersonInfoSql(final PersonBean person){
		
		return new SQL(){
			{
				SELECT("*");
				FROM("person_info");	
				if(person!=null){
					if(person.getId()!=null){
						WHERE("id=#{id}");
					}
				}
			}
		}.toString();
	}
	
	//查询人员总记录数
	public String findPersonCountSql(){
		
		return new SQL(){
			{
				SELECT("count(*)");
				FROM("person_info");	
			}
		}.toString();
	}
	//添加人员信息
	public String insertPersonSql(final PersonBean person){
		
		return new SQL(){
			{
				INSERT_INTO("person_info");
				VALUES("PERSON_CODE","#{personCode}");
				VALUES("PERSON_NAME","#{personName}");
				VALUES("PERSON_COMPANY","#{personCompany}");
				VALUES("PERSON_TITLE","#{personTitle}");
				VALUES("PERSON_PHONE","#{personPhonenumber}");
				VALUES("PERSON_EMAIL","#{personEmail}");				
				VALUES("PERSON_ADDRESS","#{personAddress}");
				VALUES("PERSON_WEBSITE","#{personWebsite}");
				VALUES("PERSON_AGE","#{personAge}");
				VALUES("PERSON_CARD","#{personCard}");
				VALUES("PERSON_SEX","#{personSex}");
				VALUES("PERSON__VCARD","#{personVcard}");
			}
		}.toString();
	}
	
	//修改人员信息
	public String updatePersonSql(final PersonBean person){
		return new SQL(){
			{				
				UPDATE("person_info");
				SET("PERSON_NAME=#{personName}");
				SET("PERSON_COMPANY=#{personCompany}");
				SET("PERSON_TITLE=#{personTitle}");
				SET("PERSON_PHONE=#{personPhonenumber}");
				SET("PERSON_EMAIL=#{personEmail}");
				SET("PERSON_ADDRESS=#{personAddress}");
				SET("PERSON_WEBSITE=#{personWebsite}");
				SET("PERSON_AGE=#{personAge}");
				SET("PERSON_CARD=#{personCard}");
				SET("PERSON_SEX=#{personSex}");
				SET("PERSON__VCARD=#{personVcard}");
				if(person!=null){
					if(person.getPersonCode()!=null&&person.getPersonCode()!=""){
						WHERE("person_code=#{personCode}");
					}
				}
				
			}
		}.toString();
	}
	
	//删除人员信息
	public String deletePersonSql(final Integer id){
		return new SQL(){
			{				
				DELETE_FROM("person_info");
				WHERE("id=#{id}");				
			}
		}.toString();
	}
}
